//
//  MCAfterGroupCapacityWeightVc.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/31.
//

import UIKit


//返回次数和重量
typealias numberInfoCapacityWightBlocks = (_ timeContent:MCCreatePlanaddDataModel?,_ index:Int?) -> Void

class MCAfterGroupCapacityWeightVc: MCBaseVc {

    @IBOutlet weak var timesOrWeightView: UIView!
    
    public var actionInfoList:MCActionInfoActionList?
    public var actionNumberOrWidgetBlocks:numberInfoCapacityWightBlocks?
    public var actionType:Int = 0
    
    public var select:Int = 0
    public var sortValue:Int = 0

    private var timesNumber:Float = 0.0
     
    private var weightNumber:Float = 0.0
    
    ///单个显示-各种数据
    lazy var lazyTimesView:DYScrollRulerView = { [unowned self] in
        let unitStr     = "次"
        let rulerHeight = DYScrollRulerView.rulerViewHeight
        var rulerView   = DYScrollRulerView.init(frame: CGRect.init(x: 5, y: 50, width: Int(ScreenWidth)-32, height: rulerHeight()), tminValue: 1, tmaxValue: 12, tstep: 1, tunit: unitStr, tNum:10, viewcontroller:self)
        rulerView.setDefaultValueAndAnimated(defaultValue: 6, animated: true)
        rulerView.bgColor       = UIColor.white
        rulerView.triangleColor = UIColor.white
        rulerView.delegate      = self
        rulerView.scrollByHand  = true
       return rulerView
    }()
    
    ///单个显示-各种数据
    lazy var lazyWeightView:DYScrollRulerView = { [unowned self] in
        let unitStr     = "KG"
        let rulerHeight = DYScrollRulerView.rulerViewHeight
        var rulerView   = DYScrollRulerView.init(frame: CGRect.init(x: 5, y: 120 + rulerHeight(), width: Int(ScreenWidth)-32, height: rulerHeight()), tminValue: 10, tmaxValue: 150, tstep: 10, tunit: unitStr, tNum:10, viewcontroller:self)
        rulerView.setDefaultValueAndAnimated(defaultValue: 70, animated: true)
        rulerView.bgColor       = UIColor.white
        rulerView.triangleColor = UIColor.white
        rulerView.delegate      = self
        rulerView.scrollByHand  = true
       return rulerView
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
     
        self.view.backgroundColor = UIColor.qmui_color(withHexString: "#F7F7F9")
        self.navigationItem.title = "训练容量"
        self.timesOrWeightView.addSubview(self.lazyTimesView)
     
        self.timesOrWeightView.addSubview(self.lazyWeightView)
        
    }
    
    
    @IBAction func completeSender(_ sender: UIButton) {
        //"actionNumber":Int(self.timesNumber),"actionType":actionType,"actionWeight":Int(self.weightNumber)
        let weightOrNumberMap:Dictionary<String,Any> = ["actionId":Int(actionInfoList?.id ?? "0") ?? 0,"actionNumber":(Int(self.timesNumber) ),"actionType":actionType,"actionWeight":(Int(self.weightNumber)),"previewUrl":actionInfoList?.previewUrl ?? "","zhName":actionInfoList?.zhName ?? "","actionLabel":actionInfoList?.actionLabel ?? ""] as Dictionary<String,Any>
        
        let timeModel = MCCreatePlanaddDataModel(JSON: weightOrNumberMap)
//        timeModel.actionId = actionInfoList?.id
//        timeModel.actionTime = Int(self.timeValue)
//        timeModel.actionType = actionType
        
        if self.actionNumberOrWidgetBlocks != nil {
            self.actionNumberOrWidgetBlocks?(timeModel,self.select)
        }
    }
}


extension MCAfterGroupCapacityWeightVc:DYScrollRulerDelegate {
    
    func dyScrollRulerViewValueChange(rulerView: DYScrollRulerView, value: Float) {
        if self.lazyTimesView == rulerView {
            self.timesNumber = value
        }else if self.lazyWeightView == rulerView {
            self.weightNumber = value
        }
        
    }
}

